<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon
      :icon-class="!isFullscreen ? 'fullscreen': 'exit-fullscreen'"
      class="fullscreen"
      @click="toggleScreen"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullscreen: false
    }
  },
  created() {
  // ESC会改变当前的全屏状态
  // 这个状态值在插件的.isFullScreen属性中
    screenfull.on('change', () => {
      console.log(screenfull.isFullscreen)
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    toggleScreen() {
      screenfull.toggle()
      this.isFullscreen = !this.isFullscreen
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
